 function ajax(obj) {
     let {
         url = '/', method = 'get', params, success, dataType = 'json'
     } = obj;

     let xhr = new XMLHttpRequest();
     var tmpArr = []
     for (var attr in params) {

         let str = attr + '=' + params[attr];
         tmpArr.push(str);
     }


     if (method == 'get') {
         url = url + '?' + tmpArr.join('&')

         xhr.open(method, url)
         xhr.send()

     } else {
         xhr.open(method, url)
         xhr.send(tmpArr.join('&'))

     }
     xhr.onload = function () {
         if (xhr.status === 200) {

             if (dataType === 'json') {
                 let obj = JSON.parse(xhr.responseText)

                 success(obj);
             } else {
                 success(xhr.responseText);
             }

         }
     }
 }